<template>
	<view>
		<swiper :indicator-dots="true" indicator-color="#ccc" indicator-active-color="red" :autoplay="true">
			<swiper-item v-for="(item,index) in imageUrls" :key="index">
				<view>
					<image :src="item.imgUrl" mode="widthFix" class="img" @tap="preImg(index)"></image>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	import {
		getLunBoTu
	} from "../../api/getData"
	export default {
		data() {
			return {
				imageUrls: [],
				imgShow: false,
			}
		},
		async beforeCreate() {
			const res = await getLunBoTu();
			this.imageUrls = res.data;
		},
		methods: {
			preImg(index){
				let data = this.imageUrls.map((o,index)=>{return o.imgUrl});
				if (this.imgShow) { //防止点击过快导致重复调用 
					return;
				}
				this.imgShow = true;
				setTimeout(() => {
					this.imgShow = false;
				}, 1000)
				setTimeout(() => {
					uni.previewImage({
						current: data[index],
						urls: data
					})
				}, 150)
			}
		}
	}
</script>

<style lang="scss">
	.img{
		width: 100%;
	}
</style>
